package codeTop;

/**
 * q230
 *
 * @author 雨凡
 * @version q230.java, v0.1
 * @date 2025/07/02/13:13
 */
public class q230 {
    public int kthSmallest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    int res = -1;
    int k;
    private void dfs(TreeNode root) {
        if (res != -1) {
            return;
        }
        if (root == null) {
            return;
        }
        dfs(root.left);
        if (k-- == 1) {
            res = root.val;
        }
        dfs(root.right);
    }
}
